
import pymysql
from conf import  *
from notify.HouseNotify import HouseNotify

class BaseStore:

    def __init__(self, host=None,port=None, user=None, password=None, database=None):
        self.host = host if host is not None else DB_HOST
        self.port = port if port is not None else DB_PORT
        self.user = user if user is not None else DB_USER
        self.password = password if password is not None else DB_PASSWORD
        self.database = database if database is not None else DB_DATABASE
        self.notify = HouseNotify()


    def execute(self,sql,param_tuple=()):
        connection = pymysql.connect(host=self.host,
                                     port=self.port,
                                     user=self.user,
                                     password=self.password,
                                     database=self.database,
                                     cursorclass=pymysql.cursors.DictCursor)

        with connection:
            with connection.cursor() as cursor:
                if param_tuple:
                   cursor.execute(sql, param_tuple)
                else:
                    cursor.execute(sql)

            # connection is not autocommit by default. So you must commit to save
            # your changes.
            connection.commit()
        return cursor


if __name__ == "__main__":
    base = BaseStore()
    print(base.host)
    print(base.password)
    print(base.user)
    print(base.database)